<!--
  Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.

  https://www.mall4j.com/

  未经允许，不可做商业用途！

  版权所有，侵权必究！
-->

<template>
  <view
    class="Mall4j page-store-settings-apply-online"
    :style="{height:windowHeight+'px'}"
  >
    <view>
      <view class="setting-info-item">
        <view class="title">
          处理人
        </view>
        <view class="input-box">
          <uni-easyinput
            v-model="infoData.handler"
            type="text"
            disabled
            :clearable="false"
            placeholder="admin"
          />
        </view>
      </view>
      <view class="setting-info-item">
        <view class="title">
          下线原因
        </view>
        <view class="input-box">
          <uni-easyinput
            v-model="infoData.offlineReason"
            type="text"
            disabled
            :clearable="false"
            placeholder="admin"
          />
        </view>
      </view>
      <view class="setting-info-item">
        <view class="title">
          下线时间
        </view>
        <view class="input-box">
          <uni-easyinput
            v-model="infoData.updateTime"
            type="text"
            disabled
            :clearable="false"
            placeholder="admin"
          />
        </view>
      </view>
      <view class="setting-info-item">
        <view class="title">
          <text class="star">
            *
          </text>
          <text>申请理由</text>
        </view>
        <view class="textarea-box">
          <textarea
            v-model="reapplyReason"
            placeholder="请输入申请理由"
            maxlength="200"
            @blur="checkInput()"
          />
        </view>
        <view
          v-show="reapplyReasonRules"
          class="tic"
        >
          请输入申请理由
        </view>
      </view>
      <view
        v-if="infoData.offlineHandleEventItemList&&infoData.offlineHandleEventItemList.length"
        class="setting-info-item"
      >
        <view class="title">
          申请历史
        </view>
        <view
          v-for="(value,item) in infoData.offlineHandleEventItemList"
          :key="item"
          class="textarea-box applyLog-box "
        >
          <view>
            <text>申请时间：</text>
            <text>{{ value.reapplyTime }}</text>
          </view>
          <view>
            <text>申请理由：</text>
            <text>{{ value.reapplyReason }}</text>
          </view>
          <view>
            <text>审核结果：</text>
            <text>{{ value.refuseReason }}</text>
          </view>
        </view>
        <!-- <view v-if="!infoData.offlineHandleEventItemList" class="textarea-box not-applyLog-box">暂无申请记录</view> -->
      </view>
    </view>
    <button
      type="primary"
      class="submit button"
      @tap="auditApply"
    >
      提交申请
    </button>
    <!-- <button v-if=" infoData.status===1" type="primary" class="submit" @tap="auditApply">提交申请</button> -->
  </view>
</template>

<script setup>
import { reactive } from 'vue'

const Data = reactive({
  infoData: {
  },
  reapplyReason: '',
  reapplyReasonRules: false,
  // 设备显示高度
  windowHeight: 0
})

const { infoData, reapplyReason, reapplyReasonRules, windowHeight } = toRefs(Data)

onLoad(() => {
  uni.getSystemInfo({
    success: (res) => {
      Data.windowHeight = res.windowHeight
    }
  })
})

onReady(() => {
  getOfflineHandleEvent()
})

// 获取店铺下线信息
const getOfflineHandleEvent = () => {
  http.request({
    url: '/shop/shopDetail/getOfflineHandleEvent',
    method: 'GET'
  }).then(({ data }) => {
    data.offlineHandleEventItemList = data.offlineHandleEventItemList.filter((element) => {
      return element.reapplyTime || element.reapplyReason || element.refuseReason
    })
    Data.infoData = data
  })
}

// 提交审核
const auditApply = () => {
  if (Data.infoData.status === 2) {
    return uni.showToast({
      title: '审核中',
      icon: 'error'
    })
  }
  Data.reapplyReasonRules = !Data.reapplyReason.trim()
  if (Data.reapplyReasonRules) return
  http.request({
    data: {
      eventId: Data.infoData.eventId,
      reapplyReason: Data.reapplyReason
    },
    url: '/shop/shopDetail/auditApply'
  }).then(() => {
    uni.showToast({
      title: '提交成功',
      icon: 'success',
      mask: true,
      success: () => {
        setTimeout(() => {
          uni.switchTab({ url: '/pages/store-settings/store-settings' })
        }, 1500)
      }
    })
  })
}

const checkInput = () => {
  Data.reapplyReasonRules = !Data.reapplyReason.trim()
}
</script>

<style lang="scss" scoped>
@use "store-settings-apply-online";
</style>
